//package com.zy.activiti.listener;
//
//import org.activiti.engine.delegate.DelegateTask;
//import org.activiti.engine.delegate.TaskListener;
//
///**
// * 监听器
// */
//public class MyTaskListener implements TaskListener {
//    /**
//     * 指定负责人
//     * @param delegateTask
//     */
//    public void notify(DelegateTask delegateTask) {
////        判断当前的任务 是 创建申请 并且  是 create事件
//        if("创建申请".equals(delegateTask.getName()) &&
//            "create".equals(delegateTask.getEventName())){
//            delegateTask.setAssignee("张三");
//        }
//
//    }
//}

package com.zy.activiti.listener;

import com.zy.activiti.service.FlowService;
import com.zy.activiti.utils.SpringContextUtil;
import lombok.extern.slf4j.Slf4j;
import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.TaskListener;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class MyTaskListener implements TaskListener {

    @Override
    public void notify(DelegateTask delegateTask) {
        log.info("eventName=={}",delegateTask.getEventName());
        if(delegateTask.getEventName().equals("assignment")){
            FlowService flowService = (FlowService)SpringContextUtil.getBean("flowService");
            log.info("flowService={}",flowService);
            flowService.createTaskEvent(delegateTask);
        }
    }
}
